<?php
    require_once "./common.php";

?>
<body style="text-align: center">
<form class="layui-form">
    <div style="margin: 20px 100px;" class="layui-input-inline">
        <h1>留言板登录</h1>
        <div class="layui-card-body" pad15="" ></div>
        <div >
            <input type="text" name="name" value="" style="width: 200px;" lay-verify="nickname" autocomplete="off" placeholder="请输入登录名" class="layui-input">
        </div>
        <div class="layui-card-body" pad15="" ></div>
        <div >
            <input type="text" name="password" value="" style="width: 200px;" lay-verify="password" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-card-body" pad15="" ></div>
        <button type="submit" class="layui-btn" lay-submit="" lay-filter="login">点击登录</button>
        <button type="submit" class="layui-btn" lay-submit="" lay-filter="register">点击注册</button>
    </div>
</form>
</body>
</html>
<script>

    layui.use(['form',"layer"], function(){
        var form = layui.form
        ,layer = layui.layer;

        form.on('submit(login)', function(data){
            $.ajax({
                url : "./demo.php",
                type : "post",
                data : {
                    option     : "login",
                    name       : data.field.name,
                    password   : data.field.password
                },
                dataType: "json",
                success : function (res) {
                    if (res.code == 1) {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 5000 //2秒关闭（如果不配置，默认是3秒）
                        });
                        parent.location.href = "./message.php";
                    }else {
                        layer.msg(res.msg, {
                            icon: 2,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        });
                    }
                }
            });
        });

        form.on('submit(register)', function(data){
            var index = layer.open({
                type: 2,
                title: '这是注册页面',
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['893px', '600px'],
                content: './register.php',
                end: function() {
                    //刷新页面,
                    layer.close(index);
                },
            });

            return false;
        });
    });
</script>